package com.tingyuge.base.thread.wang.chapter7;

/**
 * Created by xiaodao
 * date: 2019/11/29
 */
public class SynchronizedStatic {

    static {
        synchronized (SynchronizedStatic.class){
            try {
                Thread.sleep(5_000);
                System.out.println("static - "+ Thread.currentThread().getName());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized static  void m1(){
        try {
            Thread.sleep(5_000);
            System.out.println("m1 - "+ Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public synchronized static  void m2(){
        try {
            Thread.sleep(5_000);
            System.out.println("m2 - "+ Thread.currentThread().getName());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Thread(()->{
            SynchronizedStatic.m1();
        },"t1").start();
        new Thread(()->{
            SynchronizedStatic.m1();
        },"t2").start();
    }
}
